package com.origin.niuke.math;

/**
 * NC143 矩阵乘法
 * 算法：数学
 *
 * @author yezh
 * @version 1.0
 * @date 2022/11/3 21:09
 */
public class NC143 {

    public int[][] solve(int[][] a, int[][] b) {
        int n = a.length;
        int[][] ans = new int[n][n];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                for (int k = 0; k < n; k++) ans[i][j] += a[i][k] * b[k][j];
        return ans;
    }

    // 一行一行读取, 提高效率
    public int[][] solve_improve(int[][] a, int[][] b) {
        int n = a.length;
        int[][] ans = new int[n][n];
        for (int i = 0; i < n; i++)
            for (int k = 0; k < n; k++) {
                int t = a[i][k];
                for (int j = 0; j < n; j++) ans[i][j] += t * b[k][j];
            }
        return ans;
    }

}
